package com.karson.kafka.ch03.serializer;

import com.karson.kafka.ch02.serializer.Company;
import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import org.apache.kafka.common.serialization.Deserializer;

import java.util.Map;

/**
 * @author Karson Wang
 * @title ProtostuffDeserializer
 * @Description 描述
 * @Date 2020/4/26 17:16
 * @Copyright 2019-2020
 */
public class ProtostuffDeserializer implements Deserializer<Company> {

    @Override
    public void configure(Map<String, ?> configs, boolean isKey) {}

    @Override
    public Company deserialize(String topic, byte[] data) {
        if (data == null) {
            return null;
        }
        Schema schema = RuntimeSchema.getSchema(Company.class);
        Company company = new Company();
        ProtostuffIOUtil.mergeFrom(data, company, schema);
        return company;
    }

    @Override
    public void close() {}
}
